
/* GENERATED CODE:
 *  Any modifications you make are guaranteed
 *  to be deleted when this is regenerated.
 * Please edit "PROTOCOLS" inside this directory
 *
 * Names are all upper case because of "String" and "string."
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OWED.Network.Messages.General;
using OWED.Network.Messages;
using OWED.Network.Messages.Reply;


namespace OWED.Network.Messages.Reply
{
	public class PassFail: IProtocolItem 
	{
		Reason my_reason;
		bool my_pass;
		public PassFail (bool pass, Reason reason)
		{
			my_pass = pass;
			my_reason = reason;
		}
		public Reason Reason { get { return my_reason; } }
		public bool pass { get { return my_pass; } }


		public static new PassFail FromXml(XmlDocument xml)
		{
			bool pass = bool.Parse(xml.SelectSingleNode("PassFail").Attributes.GetNamedItem("pass").Value);
			XmlDocument doc;
			if (xml.SelectSingleNode("PassFail/Reason") != null) {
				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("PassFail/Reason"), true));
				Reason reason = Reason.FromXml(doc);

				return new PassFail(pass, reason);
			}
			throw new ConnectionException("Bad document supposedly of type:PassFail");
		}


		public override XmlDocument ToXml()		{
			XmlDocument doc = new XmlDocument();

			doc.AppendChild(doc.CreateElement("PassFail"));
			XmlAttribute attr;
			attr = doc.CreateAttribute("pass");
			attr.Value = my_pass.ToString();
			doc.FirstChild.Attributes.Append(attr);


			if (my_reason != null) {
				XmlNode node;
				node = doc.ImportNode(my_reason.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			return doc;
		}
	}
}
